package com.db.person.controller;

import com.db.person.bean.User_inf;
import com.db.person.service.IUserService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.ws.soap.Addressing;

@Controller
public class UserRegisterController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/register/registCode")
    public String toRegister(){
        return "regist";
    }

    @RequestMapping("/register/register")
    public String register(User_inf user_inf){

        //注册之前要给密码进行加密
        SimpleHash simpleHash = new SimpleHash("MD5",user_inf.getPassword(),user_inf.getLoginname(),1024);
        String realPwd = simpleHash.toString();

        user_inf.setPassword(realPwd);//让对象里的密码改为加密后的密码

        userService.regist(user_inf);

        return "loginForm";//注册完以后往登录上跳转

    }

    @RequestMapping("/check_Register_loginname")
    @ResponseBody
    public String checkLoginName(String loginname){
        // servcie  mapper

        User_inf user = userService.getByLoginname(loginname);

        String msg = "";
        if(user!=null){
            msg = "登录名已被使用";
        }

        return msg;
    }

}
